//
//  DZPicDetailViewController.m
//  DaZhePrivateHomeCuisineClient
//
//  Created by zouzhisheng on 15-3-9.
//  Copyright (c) 2015年 zouzhisheng. All rights reserved.
//

#import "DZPicDetailViewController.h"

@interface DZPicDetailViewController ()

@end

@implementation DZPicDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=YES;
    [self navView];
    [self addTitle:[NSString stringWithFormat:@"1/%lu",(unsigned long)self.imageArray.count]];
    self.view.backgroundColor=[UIColor blackColor];
    [self loadImages];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)loadImages{
    self.backScrollview.contentSize=CGSizeMake(SCREEN_WIDTH*self.imageArray.count, SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20);
    for (int i=0; i<self.imageArray.count; i++) {
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*i, 0, SCREEN_WIDTH, SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20)];
        DZThumbStr *model=self.imageArray[i];
        imageView.contentMode=UIViewContentModeScaleAspectFit;
        imageView.clipsToBounds=YES;
        [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",API_DOMAIN,model.picPath]] placeholderImage:IMG(@"pic")];
        [self.backScrollview addSubview:imageView];
    }
    
}
-(UIScrollView*)backScrollview{
    if (!_backScrollview) {
        _backScrollview=[[UIScrollView alloc] initWithFrame:CGRectMake(0,self.navView.bottom,SCREEN_WIDTH,SYSTEM_VERSION>=7.0?SCREEN_HEIGHT-self.navView.height:SCREEN_HEIGHT-self.navView.height-20)];
        _backScrollview.delegate=self;
        _backScrollview.pagingEnabled=YES;
        [self.view addSubview:_backScrollview];
    }
    return _backScrollview;
}
-(void)backAction:(UIButton*)bt{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSLog(@"scrollViewDidEndDecelerating  -   End of Scrolling.");
    int index = (int)(scrollView.contentOffset.x/scrollView.bounds.size.width);
    UILabel *lable=(UILabel*)[self.navView viewWithTag:100];
    lable.text=[NSString stringWithFormat:@"%d/%lu",index+1,(unsigned long)self.imageArray.count];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
